package com.henu.rescue.config;

import com.henu.rescue.utils.JwtInterceptor;
import com.henu.rescue.utils.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("adding interceptor...");
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") //拦截所有的url
                .excludePathPatterns("/admin/login") //排除 /user/login----->不拦截
                .excludePathPatterns("/admin/register")
                .excludePathPatterns("/images/**") //排除images文件下的所有文件
        ;
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/**").excludePathPatterns("/admin/login");
    }
}
